var indexRange = [1, 1500];
var maxLength = indexRange[1] - indexRange[0] + 1;
// loading
var eleContainer = document.getElementById('vcontainer');
var eleLoading = document.getElementById('vloading');
// 存储预加载的DOM对象和长度信息
var store = {
    length: 0
};
// 图片序列预加载
for ( var start = indexRange[0]; start <= indexRange[1]; start++) {
    (function (index) {
        var img = new Image();
        img.onload = function () {
            store.length++;
            // 存储预加载的图片对象
            store[index] = this;
            play();
        };
        img.onerror = function () {
            store.length++;
            play();
        };
        img.src = '/ytyz2020/assets/jpg/jljt/' + index + '.jpg';
    })(start);
}

var play = function () {
    // loading进度
    var percent = Math.round(100 * store.length / maxLength);
    eleLoading.setAttribute('data-percent', percent);
    eleLoading.style.backgroundSize = percent + '% 100%';
    // 全部加载完毕，无论成功还是失败
    if (percent == 100) {
        var index = indexRange[0];
        eleContainer.innerHTML = '';
        // 依次append图片对象
        var step = function () {
            if (store[index - 1]) {
                eleContainer.removeChild(store[index - 1]);
            }
            if(store[index]){
            	eleContainer.appendChild(store[index]);
				index++;//序列增加
			}
            // 如果超过最大限制
            if (index > indexRange[1]) {
                index=indexRange[0];
            }
        };
        // 等100%动画结束后执行播放
        //setTimeout(step, 1000);
        setInterval(function(){ step() }, 16);
    }
};